package org.session.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public final class PropertyLoader {
    public static String getProperty(final String fileName, final String key) {
        String property = null;
        Properties properties = getAllProperties(fileName);
        if (properties != null) {
            property = properties.getProperty(key);
        }

        return property;
    }

    public static Properties getAllProperties(final String fileName) {
        Properties properties = null;
        InputStream iStream = PropertyLoader.class.getClassLoader()
                .getResourceAsStream(fileName);
        if (iStream != null) {
            properties = new Properties();
            try {
                properties.load(iStream);
            } catch (IOException ioException) {
                throw new RuntimeException(ioException);
            }
        }

        return properties;
    }

    /*
     * Prevent instance escape at all costs.
     */
    private PropertyLoader() {
    }
}
